; Crappy SNDH-player
;
; parse.s
;
; May 31, 2003
;
; Anders Eriksson
; ae@dhs.nu


		section	text

scan_title:	move.w	#4,d0				;TITL = 4chars
		move.w	#2000,d1			;max header
		lea.l	string_name,a0			;address to string
		move.l	filebuffer,a1			;address to buffer

		bsr.w	parse_string			;search for string
		
		tst.l	d0				;string found?
		beq.s	.null				;nope print empty row
		move.l	d0,songname			;yes store address to print
.null:



scan_composer:	move.w	#4,d0				;TITL = 4chars
		move.w	#2000,d1			;max header
		lea.l	string_comp,a0			;address to string
		move.l	filebuffer,a1			;address to buffer

		bsr.w	parse_string			;search for string
		
		tst.l	d0				;string found?
		beq.s	.null				;nope print empty row
		move.l	d0,composer			;yes store address to print
.null:	


scan_ripper:	move.w	#4,d0				;TITL = 4chars
		move.w	#2000,d1			;max header
		lea.l	string_ripper,a0		;address to string
		move.l	filebuffer,a1			;address to buffer

		bsr.w	parse_string			;search for string
		
		tst.l	d0				;string found?
		beq.s	.null				;nope print empty row
		move.l	d0,ripper			;yes store address to print
.null:


scan_converter:	move.w	#4,d0				;TITL = 4chars
		move.w	#2000,d1			;max header
		lea.l	string_converter,a0		;address to string
		move.l	filebuffer,a1			;address to buffer

		bsr.w	parse_string			;search for string
		
		tst.l	d0				;string found?
		beq.s	.null				;nope print empty row
		move.l	d0,converter			;yes store address to print
.null:




scan_timer:	move.w	#2,d0				;TITL = 4chars
		move.w	#2000,d1			;max header
		lea.l	string_timer,a0			;address to string
		move.l	filebuffer,a1			;address to buffer

		bsr.w	parse_string			;search for string

		tst.l	d0				;string found?
		beq.s	.null				;no

		move.l	d0,timerspeed			;for printing

		move.l	d0,a0				;string is found
		lea.l	speed_ascii,a1			;speed value in ASCII
		move.w	#3-1,d7				;max three ASCII chars
.count:		move.b	(a0)+,d0			;get ASCII char
		beq.s	.done				;if zero we reached last char
		move.b	d0,(a1)+			;store ASCII char
		dbra	d7,.count			;
.done:
		moveq.l	#0,d0				;clr
		moveq.l	#0,d1				;clr
	
		move.b	-(a1),d0			;read smallest value
		beq.s	.done2				;if zero there was no value
		sub.w	#48,d0				;ASCII->value
		add.w	d0,d1				;store

		move.b	-(a1),d0			;get mid value
		beq.s	.done2				;if zero there was no value
		sub.w	#48,d0				;ASCII->value
		mulu.w	#10,d0				;deci
		add.w	d0,d1				;store
		
		move.b	-(a1),d0			;get high value
		beq.s	.done2				;if zero there was no value
		sub.w	#48,d0				;ASCII->value
		mulu.w	#100,d0				;centi
		add.w	d0,d1				;store

.done2:		move.w	d1,sndh_speed			;final SNDH calling speed
.null:		



		bra.w	parse_done

		section	data

speed_foo:		dc.l	0
speed_ascii:		dc.l	0

string_name:		dc.b	'TITL'
			even

string_comp:		dc.b	'COMM'
			even
		
string_ripper:		dc.b	'RIPP'
			even

string_timer:		dc.b	'TC'
			even

string_converter:	dc.b	'CONV'
			even

		section	text


; input
;	d0.w = number of chars to compare
;	d1.w = max bytes so scan
;	a0 = address to string to search for
;	a1 = address to buffer where to find the string
;
; output 
;	d0.l = address to string (0 = not found)

parse_string:
		move.l	a0,a2				;store first char address
		subq.w	#1,d0				;dbra..
		subq.w	#1,d1				;dbra..
		move.w	d0,d5				;number of chars in string
		move.w	d1,d7				;number of chars to scan

		moveq.l	#0,d0				;clr (nothing found)
		moveq.l	#0,d1				;clr


.loop:		move.w	d5,d6				;number of chars to scan
		move.l	a2,a0				;reset to first char
.chars:		move.b	(a1)+,d1			;get byte from buffer
		cmp.b	(a0),d1				;compare with string
		bne.s	.next				;no hit, next
		addq.l	#1,a0				;hit! next char

		dbra	d6,.chars			;next char

		move.l	a1,d0				;output address after the string in d0
		bra.s	.done				;all chars found
.next:		dbra	d7,.loop
.done:		rts

parse_done:
		